/**
 * BatchMngtAction.java - 2012-2-10
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * Project Info: China UnionPay Internet Acquiring Project
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *        
 * =============================================================================
 */
package com.lijin.batchsys.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.lijin.batchsys.framework.dao.model.BatchExecLog;
import com.lijin.batchsys.framework.dao.model.BatchExecLogDetail;
import com.lijin.batchsys.framework.enums.ErrBatchHandleMode;
import com.lijin.batchsys.framework.enums.RunningMode;
import com.lijin.batchsys.web.bean.PageInfo;
import com.lijin.batchsys.web.service.BatchLogService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Description: 批量控制Action
 *
 * (C) Copyright of China UnionPay Co., Ltd. 2010.
 *
 */
public class BatchLogAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private BatchLogService batchLogService;
	
	private List<BatchExecLog> logList = null;
	
	private List<BatchExecLogDetail> detailList = null;
    private PageInfo<BatchExecLog> pageInfo = null;
    private PageInfo<BatchExecLogDetail> detailPageInfo = null;
    
    private int curPageNo = 1;
    
    private String batchTime;
    
	/**
	 * @return the batchTime
	 */
	public String getBatchTime() {
		return batchTime;
	}

	/**
	 * @param batchTime the batchTime to set
	 */
	public void setBatchTime(String batchTime) {
		this.batchTime = batchTime;
	}

	/**
	 * @return the curPageNo
	 */
	public int getCurPageNo() {
		return curPageNo;
	}

	/**
	 * @param curPageNo the curPageNo to set
	 */
	public void setCurPageNo(int curPageNo) {
		this.curPageNo = curPageNo;
	}

	/**
	 * 获取Log的信息列表
	 * @return
	 */
	public String logShown() {
		pageInfo = new PageInfo<BatchExecLog>(curPageNo);
		batchLogService.getLogPageInfo(pageInfo);
		return "log";
	}
	
	/**
	 * 获取Log的信息列表
	 * @return
	 */
	public String detailShown() {
		
		HttpServletRequest request = ServletActionContext.getRequest();
		String batcExecLogId = request.getParameter("logId");
		String runningMode = request.getParameter("runningMode");
		RunningMode batchRunningMode = RunningMode.parseByCode(runningMode);
		
		detailList = batchLogService.listLogDetail(batcExecLogId, batchRunningMode);
	    return "detail";
	}
	
	/**
	 * 实现detaillog中的功能
	 * @return
	 */
	public String handleException() {
		
		HttpServletRequest request = ServletActionContext.getRequest();
		String logID = request.getParameter("logID");
		String detailID = request.getParameter("detailID");
		ErrBatchHandleMode handleMode = ErrBatchHandleMode.parseByCode(request.getParameter("handleMode"));
		
		String returnIndex = batchLogService.handleException(logID, detailID, handleMode);

		return returnIndex;
	}


	
	
	public List<BatchExecLog> getLogList() {
		return logList;
	}
	
	public List<BatchExecLogDetail> getDetailList() {
		return detailList;
	}
	
	public PageInfo<BatchExecLog> getPageInfo() {
		return pageInfo;
	}
	
	public PageInfo<BatchExecLogDetail> getDetailPageInfo() {
		return detailPageInfo;
	}
}